package com.explorex.infra.puma.gateway.netty.rrmp;


import com.explorex.infra.puma.gateway.netty.rrmp.codec.CipherUtil;
import com.explorex.infra.puma.gateway.netty.rrmp.codec.MessageHeader;

/**
 * @author: JacceYang
 * @createTime: 2022/09/07 20:06
 * @description:
 */
public class RrmpMessage {

    private MessageHeader header;
    private byte[] body;

    public RrmpMessage(MessageHeader header, byte[] body) {
        this.header = header;
        this.body = body;
    }

    public RrmpMessage() {
    }

    /**
     * 按协议组装向外发送的消息
     */
    public static RrmpMessage build(byte[] bodyBytes, MessageHeader messageHeader, int business) {
        byte[] bodyCheck = CipherUtil.getBodyCheckValue(bodyBytes);
        if (bodyCheck == null) {
            return null;
        }

        return new RrmpMessage();
    }


    public static RrmpMessage buildForPong(byte[] bodyBytes, MessageHeader messageHeader) {
        byte[] bodyCheck = CipherUtil.getBodyCheckValue(bodyBytes);

        return new RrmpMessage(messageHeader, bodyBytes);
    }

    public MessageHeader getHeader() {
        return header;
    }

    public void setHeader(MessageHeader header) {
        this.header = header;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

}